######## stage1:打包golang #######
#基础镜像 FROM xxx
FROM golang:1.13.1-alpine  as builder
MAINTAINER liyang.cui@sdbean.com
#设置环境变量
ENV GOPROXY=https://goproxy.cn,direct
#声明工作路径（虚拟）
WORKDIR /go/helloDocker
COPY . .
#编译go
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .
RUN ls -all

######## stage2： 从  scratch再次打包，精简体积 #######
FROM alpine:latest

RUN apk --no-cache add ca-certificates

WORKDIR /root/
# Copy the Pre-built binary file from the previous stage
COPY --from=builder /go/helloDocker/main .

RUN ls -all

#修改权限
RUN chmod +x main
# Declare volumes to mount
VOLUME ["/root/logger"]

# 容器启动命令
CMD  ["./main"]

